// 云对象教程: https://uniapp.dcloud.net.cn/uniCloud/cloud-obj
// jsdoc语法提示教程：https://ask.dcloud.net.cn/docs/#//ask.dcloud.net.cn/article/129
const db = uniCloud.database();
const {
	result
} = require("xzs-utils");
module.exports = {
	_before: function() { // 通用预处理器
		this.startTime = Date.now();
	},
	get: async function() {
		let data = await db.collection("mysit-news-categories").field({
			_id: true,
			name: true,
			sort: true,
			description: true,
			article_count: true
		}).orderBy("sort", "asc").get()
		return result(0, "success", data, data.data.length)
	},
	_after: function(error, result) {
		if (error) {
			throw error // 如果方法抛出错误，也直接抛出不处理
		}
		result.timeCost = Date.now() - this.startTime
		return result
	}
}